﻿namespace _1._2._11._04.DownloadFileAndExceptions
{
    using System;
    using System.Net;

    class DownloadFileAndExceptions
    {
        // 1.2.11.04. Write a program that downloads a file from Internet (e.g. http://www.devbg.org/img/Logo-BASD.jpg)
        // and stores it the current directory. Find in Google how to download files in C#.
        // Be sure to catch all exceptions and to free any used resources in the finally block.
        static void Main()
        {
            WebClient wc = new WebClient(); // wc = web client :D
            try
            {
                wc.DownloadFile("http://telerikacademy.com/Content/Images/sunLight.png", @"c:\telerikAcademy.png");
            }
            catch (ArgumentNullException)
            {
                Console.WriteLine("Somewhere something gets null. Good luck in finding it.");
            }
            catch (WebException)
            {
                Console.WriteLine("Rofl! Your ISP is bad or your firewall is mad - no internet connection, atm.");
            }
            catch (NotSupportedException)
            {
                Console.WriteLine("An impossible function was proceeded.");
            }
            finally
            {
                wc.Dispose();
            }
        }
    }
}
